package com.vinny.springbootflowable2.util;

import com.vinny.springbootflowable2.model.SysUser;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import jakarta.servlet.http.HttpSession;

public class UserSessionUtil {
    private static final String USER_SESSION_KEY = "current_user";
    
    public static void setCurrentUser(SysUser user) {
        HttpSession session = getSession();
        session.setAttribute(USER_SESSION_KEY, user);
    }
    
    public static SysUser getCurrentUser() {
        HttpSession session = getSession();
        return (SysUser) session.getAttribute(USER_SESSION_KEY);
    }
    
    public static void removeCurrentUser() {
        HttpSession session = getSession();
        session.removeAttribute(USER_SESSION_KEY);
    }
    
    private static HttpSession getSession() {
        ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        return attr.getRequest().getSession(true);
    }
} 